package com.foreknow.test;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SetDemo {
    public static void main(String[] args) {
        //创建一个Set集合容器
        Set<Employee> set = new HashSet<>();
        //向集合中添加元素
        Employee e1 = new Employee();
        e1.setEid(101);
        e1.setName("fender");
        Employee e2 = new Employee();
        e2.setEid(102);
        e2.setName("gibson");
        //将员工添加到Set集合中
        set.add(e1);
        set.add(e2);
        //可以使用迭代器获取Set集合中所有元素
        Iterator<Employee> it = set.iterator();
        while (it.hasNext()) {
            Employee employee = it.next();
            System.out.println(employee.getEid() + " " + employee.getName());
        }
    }
}
